package Servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

@WebServlet("/ServletDemo08")
public class ServletDemo08 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//设置编码
        request.setCharacterEncoding("utf-8");
//        String username = request.getParameter("username");
//        String[] subjects = request.getParameterValues("subject");
//   for (int i=0;i<subjects.length;i++){
//       System.out.println(subjects[i]);
        //获取所有请求参数的名称
//      Enumeration<String> parameterNames = request.getParameterNames();
//       while (parameterNames.hasMoreElements()){
//           String s = parameterNames.nextElement();
//            String parameter = request.getParameter(s);
//           System.out.println(parameter);
        Map<String, String[]> parameterMap = request.getParameterMap();
        //
        Set<String> strings = parameterMap.keySet();
        //获取key
        for (String string:strings) {
            String[] strings1 = parameterMap.get(string);
            for (String value:strings1) {
                System.out.println(string+":"+value);

                }
            }
        }
    }



